/*-------------------------------------------------------------------------
   Copyright (C) 2010 One Laptop per Child

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

   In other words, you are welcome to use, share and improve this program.
   You are forbidden to forbid anyone else to use, share and improve
   what you give them.   Help stamp out software-hoarding!

   As a special exception, you may use this file as part of a free software
   library for the XO of the One Laptop per Child project without restriction.
   Specifically, if other files instantiate
   templates or use macros or inline functions from this file, or you compile
   this file and link it with other files to produce an executable, this
   file does not by itself cause the resulting executable to be covered by
   the GNU General Public License.  This exception does not however
   invalidate any other reasons why the executable file might be covered by
   the GNU General Public License.
-------------------------------------------------------------------------*/

#ifndef POWER_H
#define POWER_H

#include "chip.h"

#define OEMSYS_POWEROFF	0x00
#define OEMSYS_BOOTED   0x03
#define OEMSYS_STANDBY  0x01
#define OEMSYS_STRANGE  0x02

#define DO_NOTHING				0
#define BOARD_ON				1
#define WAIT_MAIN_ON			2
#define SYSTEM_IN_WORKING		3
#define RSMRST_DELAY			4
#define RSMRST					5
#define PWR_BUT_STROBE_DELAY	6
#define PWR_BUT_STROBE			7
#define MAIN_ON_DELAY			8
#define PWR_GOOD				9
#define WAIT_PCI_RST			10
#define SYSTEM_BOOTED			11
#define NO_BOOT_DELAY			12
#define WAIT_PORT_80			13
#define POWER_OFF_RESTART_DELAY	14
#define WATCH_FOR_SOFT_OFF		15
#define TURN_OFF				16
#define WAIT_POLL_BATTERY		17
#define ENFORCE_MIN_OFF_TIME	18
#define FINAL_FLICKER_ON		19
#define FINAL_FLICKER_OFF		20
#define START_FINAL_FLICKER		21
#define WAIT_ENABLE_BATTERY		22
#define PRE_VCORE_DELAY			23
#define EN_VCORE				24
#define PRE_EN_1_8V_PMIC_DELAY	25
#define	EN_1_8V_PMIC			26
#define PRE_REMAINING_RAILS_DELAY	27
#define REMAINING_RAILS			28
#define WAIT_ALL_PWRGOOD		29
#define PRE_SOC_RESET_DELAY		30
#define DISABLE_SOC_RESET		31
#define WAIT_SYS_RESET			32
#define PRE_EN_1_2V_DELAY		33
#define EN_1_2V					34
#define PRE_EN_1_8V_GPIO_DELAY	35
#define EN_1_8V_GPIO			36
#define PRE_DISABLE_SOC_RESET_DELAY	37
#define START_POWER_UP			38

#define HOST_POWERED_OFF		1
#define HOST_ON					2
// #define HOST_IN_SUSPEND			3
#define HOST_TRYING_TO_BOOT		4
// #define HOST_WAKEUP_GAMEKEY		5

// Magic values to put in FIRMWARE_ID for operations
// at power up.
#define EC_RESET_AUTOPOWERON		0x01

void power_init_module(void);
void power_start_host(void);
void set_min_off_time(int val);
void power_process(void);
// void turn_board_off(void);
void power_command_shutdown(void);
void power_command_powercycle(void);

unsigned char power_host_is_on(void);
unsigned char power_host_is_off(void);
unsigned char power_but_in_dbounce(void);

void power_dcon(unsigned char on);
void power_usb(unsigned char on);
void power_sd2(unsigned char on);

extern unsigned char SystemState;

unsigned char host_in_suspend(void);
unsigned char host_suspending(void);
void set_suspend_hint(unsigned char s);
void check_soc_sleep(void);

void autopower_init(void);

#endif
